package com.zxl.designpattern.creator.factory;

import com.zxl.designpattern.creator.factory.abstractpattern.AbstractFactoryStore;
import com.zxl.designpattern.creator.factory.abstractpattern.IAbstractFactory;
import com.zxl.designpattern.creator.factory.methodpattern.FactoryMethodStore;
import com.zxl.designpattern.creator.factory.methodpattern.HuaWeiPhoneFactory;
import com.zxl.designpattern.creator.factory.pojo.Laptop;
import com.zxl.designpattern.creator.factory.pojo.Phone;

/**
 * @author zxl
 * @version 1.0
 * @description 工厂测试类
 * @date 2025/5/31 19:07
 */
public class Test {

    public static void main(String[] args) {
        testSimpleFactory();
        testFactoryMethod();
        testAbstractFactory();
    }

    /**
     *  测试简单工厂模式
     */
    public static void testSimpleFactory() {
        System.out.println("================测试简单工厂=======================");
        PhoneStore coffeeStore = new PhoneStore();
        Phone coffee = coffeeStore.buyPhone("MI");
        System.out.println(coffee.getName());
    }

    /**
     *  测试工厂方法模式
     */
    public static void testFactoryMethod() {
        System.out.println("================测试工厂方法=======================");
        FactoryMethodStore coffeeStore = new FactoryMethodStore();
        coffeeStore.setFactory(new HuaWeiPhoneFactory());
        Phone coffee = coffeeStore.buyPhone();
        System.out.println(coffee.getName());
    }

    /**
     *  测试抽象工厂
     */
    public static void testAbstractFactory() {
        System.out.println("================测试工厂方法=======================");
        IAbstractFactory factory = AbstractFactoryStore.getFactory2("mi");
        Laptop laptop = factory.createLaptop();
        Phone phone = factory.createPhone();
        System.out.println(laptop.getName());
        System.out.println(phone.getName());
    }
}
